package com.example.project_dish.Capital;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.project_dish.R;

import java.util.List;

public class AdapterComment extends BaseAdapter {
    Context context;
    List<Comment> data;

    public AdapterComment(Context context, List<Comment> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if(view == null){
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.activity_comment,null);
            holder.commentName = (TextView) view.findViewById(R.id.comment_name);
            holder.star = (ImageView) view.findViewById(R.id.comment_star);
            holder.commentContent = (TextView) view.findViewById(R.id.comment_content);
            view.setTag(holder);
        }else {
            holder = (ViewHolder) view.getTag();
        }
        holder.commentName.setText(data.get(i).getName());
        holder.star.setBackground(data.get(i).getStar());
        holder.commentContent.setText(data.get(i).getContent());
        return view;
    }

    public void addComment(Comment comment){
        data.add(comment);
        notifyDataSetChanged();
    }
    public static class ViewHolder{
        private TextView commentName;
        private TextView commentContent;
        private ImageView star;
    }


}
